<template>
	<view class="containers" style="padding-bottom: 100px;">
		<!-- DIY组件 -->
		<diy-component :diyItems="items"></diy-component>

		<!-- 底线 -->
		<view class="title-footer p-r">
			<text class="f-24 col-9 cont">我是有底线的</text>
			<view class="hr"></view>
	    </view>
		<tabbar :showmenu="menu_type" current="5"></tabbar>
	</view>
</template>

<script>
	import diyComponent from '@/components/diy/index.vue'
	import tabbar from '@/components/tabbar/tabbar.vue';
	let request = require('../../utils/require');
	const app = getApp();
	export default {
		components: {
			diyComponent,
			tabbar
		},
		data() {
			return {
				// 页面参数
				options: {},
				menu_type: uni.getStorageSync('menu_type'),
				// 页面元素
				items: {},
				scrollTop: 0,
				indexId: 3,
				item: {
					indexId: 0,
					colors: '#fff;',
					isfujin: '',
					isshop: ''
				},
				tankuangisshows:false
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			// 当前页面参数
			this.options = options;

			this.getPageData();
			this.kefulistFun()
		},
		/**
		 * 分享当前页面
		 */
		onShareAppMessage() {
			var thisUserInfo = uni.getStorageSync('userInfo');
			var sett =  uni.getStorageSync('setting');
			var shareObj = {
				title: sett.name,
				desc: sett.desc,
				// 默认是小程序的名称(可以写果鸽集运等)
				path: '/pages/home/index?scene=uid%3A' + thisUserInfo.user_id,
				// 默认是当前页面，必须是以‘/’开头的完整路径
				imageUrl: '',
				//自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
				success: function(res) {
					// 转发成功之后的回调
					if (res.errMsg == 'shareAppMessage:ok') {
					}
				},
				fail: function() {
					// 转发失败之后的回调
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						// 用户取消转发
					} else {
						if (res.errMsg == 'shareAppMessage:fail') {
						}
					}
				}
			};
			return shareObj;
		},
		/**
		 * 下拉刷新
		 */
		// /**
		//  * 返回顶部
		//  */
		// goTop: function(t) {
		//   this.setData({
		//     scrollTop: 0
		//   });
		// },
		// scroll: function(t) {
		//   this.setData({
		//     indexSearch: t.detail.scrollTop
		//   }), t.detail.scrollTop > 300 ? this.setData({
		//     floorstatus: !0
		//   }) : this.setData({
		//     floorstatus: !1
		//   });
		// },
		onPullDownRefresh: function() {
			// 获取首页数据
			this.getPageData(function() {
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			//客服
			kefulistFun() {
			    var that = this;
			    var data = {
			        token: uni.getStorageSync('token')
			    };
			    request.post(`index.php?s=/api/page/service&wxapp_id=` + uni.getStorageSync('web_id'), data).then((res) => {
			        if (res.data.code == 1) {
			            that.kefulist =  res.data.data.values
						uni.setStorageSync('service_phone',res.data.data.values.service_phone)
			            console.log(res, 'kefu');
			        } else {
			            uni.showToast({
			                title: res.data.msg,
			                icon: 'none'
			            });
			        }
			    });
			},

			/**
			 * 加载页面数据
			 */
			getPageData: function(callback) {
				let that = this;
				request.get(`index.php?s=/api/page/index&wxapp_id=` + uni.getStorageSync('web_id'), {page_id: that.options.page_id || 10001}).then(result => {
					if (result.data.code == 1) {
						that.setPageBar(result.data.data.page);
						that.items = result.data.data.items;
						if (typeof callback === 'function') {
							callback();
						}
					}
				});
			},
			tankuangguanbi() {
				this.tankuangisshows = false
			},

			tankuang() {
				this.tankuangisshows = true
			},
			/**
			 * 设置顶部导航栏
			 */
			setPageBar: function(page) {
				// 设置页面标题
				uni.setNavigationBarTitle({
					title: page.params.title
				}); // 设置navbar标题、颜色

				uni.setNavigationBarColor({
					frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
					backgroundColor: page.style.titleBackgroundColor
				});
			}
		}
	};
</script>
<style>
	@import './index.css';

	.containers {
		background: #fff;
	}

	.baoguo_yubaogo {
		position: fixed;
		z-index: 1000;
		top: 70%;
		right: 10%;
	}

	.baoguo_yubaogo_btns {
		font-size: 30rpx;
		color: #fff;
		background-image: linear-gradient(to bottom right, #63DCC9, #19BCA3);
		border-radius: 50%;
		width: 70rpx;
		height: 70rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 25rpx;
		letter-spacing: 0.15rem;
	}

	.uni-app--maxwidth {
		position: relative;
	}
</style>
